Page({

  onLoad(options) {
    this.data.maxTryCount = 10
    this.doRedirect(options)
  },
  doRedirect(options) {
    this.data.maxTryCount -= 1
    var plugin = requirePlugin("shop2cn-shopapis-plugin");
    if (options.tar) {
      const url = decodeURIComponent(options.tar)
      const fullPath = plugin.getFullPath(url)
      console.log('shopPlugin redirectTo:', fullPath)
      if (!fullPath && this.data.maxTryCount > 0) {
        setTimeout(() => {
          console.log('doRedirect count ' + this.data.maxTryCount)
          this.doRedirect(options)
        }, 500);
        return
      }
      wx.redirectTo({url: fullPath}) 
    } else if (options.scene) {
      plugin.parseRedirect(options).then((url) => {
        if (!url && this.data.maxTryCount > 0) {
          setTimeout(() => {
            this.doRedirect(options)
          }, 500);
          return
        }
        wx.redirectTo({url: url})
      })
    }
  }
 
})
